package com.ricky04.aysnc;

import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * Created by bgt on 2018/5/6.
 */
@Component
public class MyAsync {
    /**
     *
     */
    public void doSomeThing() {
        System.out.println("步骤2");
        try {
            for (int i = 0; i < 3; i++) {
                System.out.println("模拟耗时");
                Thread.sleep(500);
            }
        } catch (Exception e) {

        }
        System.out.println("步骤3");
    }

    /**
     * 要使此注解生效  则需要开启@EnableAsync
     */
    @Async
    public void doSomeThing2() {
        System.out.println("async2步骤2");
        try {
            for (int i = 0; i < 3; i++) {
                System.out.println("模拟耗时");
                Thread.sleep(500);
            }
        } catch (Exception e) {

        }
        System.out.println("async2步骤3");
    }
}
